<?php

/**
 * This is the model class for table "shop_product".
 *
 * The followings are the available columns in table 'shop_product':
 * @property integer $prid
 * @property string $pr_name
 * @property string $pr_stardate
 * @property string $pr_enddate
 * @property string $pr_url
 * @property string $pr_small_content
 * @property string $pr_content
 * @property string $pr_meta
 * @property string $pr_description
 * @property string $pr_datecreate
 * @property string $pr_dateup
 * @property integer $flag
 * @property integer $showid
 * @property integer $position
 * @property integer $cate_id
 * @property integer $pr_img_id
 * @property integer $locaID
 * @property integer $ctiID
 * @property integer $shopid
 * @property integer $disID
 * @property integer $discount
 * @property string $asia_name
 * @property string $avatar
 * @property integer $uid
 */
class ShopProduct extends CActiveRecord
{
	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'shop_product';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('pr_name, pr_datecreate, pr_dateup, position, discount, asia_name, avatar', 'required'),
			array('flag, showid, position, cate_id, pr_img_id, locaID, ctiID, shopid, disID, discount, uid', 'numerical', 'integerOnly'=>true),
			array('pr_name', 'length', 'max'=>100),
			array('pr_url, asia_name', 'length', 'max'=>200),
			array('pr_small_content, pr_description', 'length', 'max'=>500),
			array('pr_meta', 'length', 'max'=>300),
			
			array('pr_stardate, pr_enddate, pr_content', 'safe'),
                        array('avatar', 'file', 'types'=>'jpeg,jpg, gif, png', 'maxSize' => 100000, 'allowEmpty' => true, 'tooLarge' => 'Hình ảnh không được vượt quá 100kb. Bạn phải giảm dung lượng file ảnh .'),

			// The following rule is used by search().
			// @todo Please remove those attributes that should not be searched.
			array('prid, pr_name, pr_stardate, pr_enddate, pr_url, pr_small_content, pr_content, pr_meta, pr_description, pr_datecreate, pr_dateup, flag, showid, position, cate_id, pr_img_id, locaID, ctiID, shopid, disID, discount, asia_name, avatar, uid', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'prid' => 'Prid',
			'pr_name' => 'Tên sản phẩm',
			'pr_stardate' => 'Ngày bắt đầu',
			'pr_enddate' => 'Ngày kết thúc',
			'pr_url' => 'Url',
			'pr_small_content' => 'Pr Small Content',
			'pr_content' => 'Nội dung',
			'pr_meta' => 'Từ khóa tìm kiếm',
			'pr_description' => 'Mô tả ngắn',
			'pr_datecreate' => 'Ngày tạo',
			'pr_dateup' => 'Ngày cập nhật',
			'flag' => 'Trạng thái',
			'showid' => 'Showid',
			'position' => 'Vị trí',
			'cate_id' => 'Danh mục',
			'pr_img_id' => 'Pr Img',
			'locaID' => 'Loca',
			'ctiID' => 'Tỉnh/thành',
			'shopid' => 'Gian hàng',
			'disID' => 'Dis',
			'discount' => 'Giảm giá (%)',
			'asia_name' => 'Tên hiễn thị url',
			'avatar' => 'Hình ảnh',
			'uid' => 'Uid',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 *
	 * Typical usecase:
	 * - Initialize the model fields with values from filter form.
	 * - Execute this method to get CActiveDataProvider instance which will filter
	 * models according to data in model fields.
	 * - Pass data provider to CGridView, CListView or any similar widget.
	 *
	 * @return CActiveDataProvider the data provider that can return the models
	 * based on the search/filter conditions.
	 */
	public function search()
	{
		// @todo Please modify the following code to remove attributes that should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('prid',$this->prid);
		$criteria->compare('pr_name',$this->pr_name,true);
		$criteria->compare('pr_stardate',$this->pr_stardate,true);
		$criteria->compare('pr_enddate',$this->pr_enddate,true);
		$criteria->compare('pr_url',$this->pr_url,true);
		$criteria->compare('pr_small_content',$this->pr_small_content,true);
		$criteria->compare('pr_content',$this->pr_content,true);
		$criteria->compare('pr_meta',$this->pr_meta,true);
		$criteria->compare('pr_description',$this->pr_description,true);
		$criteria->compare('pr_datecreate',$this->pr_datecreate,true);
		$criteria->compare('pr_dateup',$this->pr_dateup,true);
		$criteria->compare('flag',$this->flag);
		$criteria->compare('showid',$this->showid);
		$criteria->compare('position',$this->position);
		$criteria->compare('cate_id',$this->cate_id);
		$criteria->compare('pr_img_id',$this->pr_img_id);
		$criteria->compare('locaID',$this->locaID);
		$criteria->compare('ctiID',$this->ctiID);
		$criteria->compare('shopid',$this->shopid);
		$criteria->compare('disID',$this->disID);
		$criteria->compare('discount',$this->discount);
		$criteria->compare('asia_name',$this->asia_name,true);
		$criteria->compare('avatar',$this->avatar,true);
		$criteria->compare('uid',$this->uid);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}

	/**
	 * Returns the static model of the specified AR class.
	 * Please note that you should have this exact method in all your CActiveRecord descendants!
	 * @param string $className active record class name.
	 * @return ShopProduct the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}
}
